package com.greatchn.single_login.config;

import com.greatchn.single_login.filter.ExceptionFilter;
import com.greatchn.single_login.filter.TokenFilter;
import org.springframework.security.config.annotation.SecurityConfigurerAdapter;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @AuthTokenConfig:
 * @author: ZBoHang
 * @time: 2023/2/8 13:45
 */
@Component
public class AuthTokenConfig extends SecurityConfigurerAdapter<DefaultSecurityFilterChain, HttpSecurity> {

    @Resource
    private TokenFilter tokenFilter;
    @Resource
    private ExceptionFilter exceptionFilter;

    @Override
    public void configure(HttpSecurity builder) {

        builder.addFilterBefore(this.tokenFilter, UsernamePasswordAuthenticationFilter.class)
                .addFilterBefore(this.exceptionFilter, TokenFilter.class);
    }
}
